package haxibiao

import "fmt"

func IsHappy(n int) bool {
	if n == 1 {
		return true
	}
	list := map[int]int{}
	for n > 1 {
		list[n]++
		if ok := judgeAgain(list); !ok {
			return false
		}
		if n = total(n); n == 1 {
			return true
		}
	}
	return false
}

func judgeAgain(list map[int]int) bool {
	for _, v := range list {
		if v > 1 {
			return false
		}
	}
	return true
}

func total(n int) int {
	ans := 0
	for n >= 1 {
		ans += (n % 10) * (n % 10)
		n /= 10
		fmt.Println(ans, n)
	}
	return ans
}
